package com.labelimage.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.labelimage.bean.entity.DatasetEntity;
import com.labelimage.bean.vo.DatasetVo;
import com.labelimage.common.utils.PageUtils;
import com.labelimage.dao.DatasetDao;
import com.labelimage.service.DatasetService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


@Service("datasetService")
public class DatasetServiceImpl extends ServiceImpl<DatasetDao, DatasetEntity> implements DatasetService {

    @Override
    public PageUtils<DatasetVo> load(Integer pageNum) {
        Page<DatasetEntity> page = new Page<>(pageNum,5);
        Page<DatasetEntity> datasetEntityPage = this.page(page);
        List<DatasetVo> datasetVoList = datasetEntityPage.getRecords().stream().map(datasetEntity -> {
            DatasetVo datasetVo = new DatasetVo();
            BeanUtil.copyProperties(datasetEntity, datasetVo);
            return datasetVo;
        }).collect(Collectors.toList());
       return new PageUtils<>(datasetVoList,datasetEntityPage);
    }
}